package com.RKB.dao;

import com.RKB.pojo.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.*;

@Repository
@Mapper
public interface questionbankDao {
    @Select("select * from questionbank")
    public List<questionbank> findAll();

    @Select("select * from questionbank where question like CONCAT('%' ,#{question}, '%' )")
    public List<questionbank> findByQuestion(String question);

    @Select("select * from questionbank where type like CONCAT('%' ,#{type}, '%')")
    public List<questionbank> findByType(String type);

    @Select("select id from questionbank where type like CONCAT('%' ,#{type}, '%')")
    public List<Integer> findIdByType(String type);

    @Insert("insert into questionbank values(null,#{question}," +
            "#{anwserA},#{anwserB},#{anwserC},#{anwserD},#{correct},#{type},#{analysis})")
    public void toAddQuestion(questionbank addquestion);

    @Select("select * from questionbank where id = #{id}")
    public List<questionbank> findById(Integer id);

    @Select("select type from questionbank where id = #{id}")
    public String findTypeById(Integer id);

    @Select("select id,correct from questionbank ")
    public List<answerType> findCorrect();

    @Insert("insert into err_log (`id`,`user_id`,`error_id`) values (null,#{user_id},#{error_id})")
    public void insertErr_log(Err_log errLog);


    public void insertErr_question(@Param("List") List<Err_questionbank> err_questionbankList);

    @Select("select `time`,error_id from err_log where `user_id` = #{username} AND `time` >= DATE_SUB(NOW(), INTERVAL 7 DAY)")
    public List<Err_questionIds_time> getErr_ids(String username);


}
